package org.jdcenter.server.xb.metadata;

import org.jdcenter.Constants;
import org.jdcenter.server.xb.parser.ParserException;
import org.picocontainer.Parameter;
import org.picocontainer.parameters.ComponentParameter;
import org.picocontainer.parameters.ConstantParameter;

/**
 * @author miao
 * @since 2008-12-02
 *
 */
public class ParameterMateData {
	
	private String type;
	private String value;
	
	public ParameterMateData(String type,String value){
		this.type = type;
		this.value = value;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public Parameter getParameter(){
		if(type.equalsIgnoreCase(Constants.inject)){
			return new ComponentParameter(value);
		}else{
			return new ConstantParameter(getValueObj());
		}
	}
	
	private Object getValueObj(){
		
		if(type.equalsIgnoreCase("string")){
			return new String(value);
		}
		if(type.equalsIgnoreCase("int") || type.equalsIgnoreCase("integer")){
			return new Integer(value);
		}
		if(type.equalsIgnoreCase("short")){
			return new Short(value);
		}
		if(type.equalsIgnoreCase("byte")){
			return new Byte(value);
		}
		if(type.equalsIgnoreCase("long")){
			return new Long(value);
		}
		if(type.equalsIgnoreCase("float")){
			return new Float(value);
		}
		if(type.equalsIgnoreCase("double")){
			return new Double(value);
		}
		if(type.equalsIgnoreCase("boolean")){
			return new Boolean(value);
		}
		throw new ParserException(type+" is not type to deploy");
	}

}
